package com.junjie.checkin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.pagehelper.Page;
import com.junjie.checkin.entity.TStudentGift;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.security.core.parameters.P;

/**
 * @author 洪浚杰
 * @description 礼品兑换记录mapper
 * @date 2025/6/17 15:04
 */
@Mapper
public interface StudentGiftMapper extends BaseMapper<TStudentGift> {
    /**
     * 查询某个礼品的兑换记录
     * @param id 礼品id
     * @param keyword 关键字
     * @return 礼品列表
     */
    Page<TStudentGift> pageQueryGiftOrder(@Param("id") Integer id,
                                          @Param("keyword")String keyword);

    /**
     * 根据用户id查询
     * @param userId 用户id
     * @param keyword 关键字
     * @return 礼品列表
     */
    Page<TStudentGift> pageQueryGiftOrderByUserId(@Param("userId")Integer userId,
                                                  @Param("keyword")String keyword);

    /**
     * 活动礼品已领取数量
     * @param id 礼品id
     * @return 领取数量
     */
    @Select("select count(*) from t_student_gift where gift_id = #{id} and status = 1")
    Long selectDistributedCount(@Param("id")Integer id);
}
